﻿Shader "BToolkit/FlowLight"
{
	Properties
	{
		[HideInInspector]
		_MainTex("Base (RGB), Alpha (A)", 2D) = "black" {}
		_LightTex("Light", 2D) = "black" {}
		_Color("Color", Color) = (1,1,1,1)
		_LightScale("LightScale", Range(0, 5)) = 2.5
		_Intensity("Intensity", Float) = 1
		_Speed("Speed", Float) = 0.2
		_Angle("Angle", Float) = 0.5
	}

		SubShader
		{
			LOD 100
			Tags
			{
				"Queue" = "Transparent"
				"IgnoreProjector" = "True"
				"RenderType" = "Transparent"
			}
			Pass
			{
				Cull Off
				Lighting Off
				ZWrite Off
				Fog { Mode Off }
				Blend SrcAlpha OneMinusSrcAlpha
				CGPROGRAM
				#pragma vertex vert
				#pragma fragment frag
				#include "UnityCG.cginc"
				sampler2D _MainTex;
				float4 _MainTex_ST;
				sampler2D _LightTex;
				float4 _LightTex_ST;
				float4 _Color;
				float _LightScale,_Speed,_Angle,_Intensity;
				struct appdata_t
				{
					float4 vertex : POSITION;
					float2 texcoord : TEXCOORD0;
					fixed4 color : COLOR;
				};

				struct v2f
				{
					float4 vertex : SV_POSITION;
					float2 texcoord : TEXCOORD0;
					fixed4 color : COLOR;
				};

				v2f o;
				v2f vert(appdata_t v)
				{
					o.vertex = UnityObjectToClipPos(v.vertex);
					o.texcoord = TRANSFORM_TEX(v.texcoord,_MainTex);
					o.color = v.color;
					return o;
				}

				fixed4 frag(v2f IN) : COLOR
				{
					fixed4 main = tex2D(_MainTex, IN.texcoord);
					float2 newUV = IN.texcoord.xy - float2(0.5,0.5);
					newUV = float2(newUV.x * cos(_Angle) - newUV.y * sin(_Angle),newUV.y * cos(_Angle) + newUV.x * sin(_Angle));
					newUV += float2(0.5,0.5);
					newUV.x /= _LightScale;
					half lightU = newUV.x - frac(_Time.y * _Speed);
					half2 lightUV = half2(lightU, 0) * _LightTex_ST.xy + _LightTex_ST.zw;
					fixed4 light = tex2D(_LightTex, lightUV) * _Intensity;
					fixed4 col = main + main * light.r * _Color;
					return  col * IN.color;
				}
				ENDCG
			}
		}
}